import math
class BasicTrigo(object):
    cdef static float dot(float A[2],float B[2]):
        return A[0]*B[0]+B[1]*A[1]
    
    
    cdef static float norm(float A[2]):
        return math.sqrt(A[0]*A[0]+A[1]*A[1])

    cdef static float norm2(float A[2]):
        return A[0]*A[0]+A[1]*A[1]
    
    cdef static float[2] sub(float A[2],float B[2]):
        cdef float C[2]
        C[0]=A[0]-B[0]
        C[1]=A[1]-B[1]
        return C
    cdef static float[2] add(float A[2],float B[2]):
        cdef float C[2]
        C[0]=B[0]+A[0]
        C[1]=B[1]+A[1]
        return C
    cdef static float[2] scalar(float A[2],float f):
        cdef float C[2]
        C[0]=A[0]*f
        C[1]=A[1]*f
        return C
    
    cdef float[2] normalizedCopy(float A[2]):
        cdef float n=BasicTrigo.norm(A)
        cdef float C[2]
        C[0]=A[0]/n
        C[1]=A[1]/n
        return C
    
    cdef static float[2][2] project(float A[2],float B[2],float C[2]):
        cdef float[2] Parallel, Perpendicular
        cdef float r
        cdef float [2] AB=BasicTrigo.sub(B,A), AC=BasicTrigo.sub(C,A)
        r=BasicTrigo.dot(AC,AB)
        r/=BasicTrigo.norm2(AB)
        cdef float[2] para,perp
        
        para=BasicTrigo.add(A,BasicTrigo.scalar(AB,r))
        perp=BasicTrigo.sub(AC,para)
        
        return (para,perp)
        
        
class Body(BasicTrigo):
    cdef float position[2]
    cdef float speed[2]
    cdef float mass,momentum,angle,omega
    
    def __init__(self):
        self.setMass(m)
    
    def setMass(self,m):
        self.mass=float(m)
    
    def setMomentum(self,m):
        self.momentum=float(m)
        
    def setPosition(self,pos):
        self.position[0]=float(pos[0])
        self.position[1]=float(pos[1])
    
    def getPosition(self,pos):
        return position
    
    def setPosition(self,pos):
        self.position[0]=float(pos[0])
        self.position[1]=float(pos[1])
    
    def getPosition(self,pos):
        return position
            
